<template>
	<view class="wrap">
		<view class="back" @tap="back">
			<image :src="$imgUrl('/lt_back.png')" mode="scaleToFill" />
		</view>
		<view class="content">
				<u--form
					labelPosition="left"
					:model="model1"
					ref="form1"
					labelWidth="140rpx"
				>
				<u-form-item
						label="昵称："
						prop="userInfo.name"
						ref="item1"
					>
						<u--input
							v-model="model1.userInfo.name"
							border="none"
							placeholder="请输入微信号"
						></u--input>
					</u-form-item>
					<u-form-item
						label="手机号"
						prop="userInfo.moblie"
						ref="item2"
					>
					<u--input
							v-model="model1.userInfo.moblie"
							type="number"
							disabledColor="#ffffff"
							placeholder="请输入手机号"
							border="none"
						></u--input>
				
					</u-form-item>
					<u-form-item
						label="生日"
						prop="userInfo.birthday"
						@click="showBirthday = true; hideKeyboard()"
						ref="item3"
					>
						<u--input
							v-model="model1.userInfo.birthday"
							disabled
							disabledColor="#ffffff"
							placeholder="请选择生日"
							border="none"
						></u--input>
						
					</u-form-item>
			<!-- 		<u-form-item
						label="头像"
						prop="userInfo.head"
						
						ref="item4"
					>
					<u-upload
						width="180rpx"
						height="180rpx"
						:fileList="fileList1"
						@afterRead="afterRead"
						@delete="deletePic"
						name="1"
						multiple
						:maxCount="10"
					></u-upload>
					</u-form-item> -->
					<!-- <u-form-item label="头像" prop="userInfo.head" ref="item1">
						<u-upload @delete="del" width="160" height="160" :fileList="tpList" :compressed="true"
							:maxDuration="60" :capture="[ 'album']" name="2" @afterRead="afterReada" 
							:maxCount="1"></u-upload>
					</u-form-item> -->
					<u-form-item
						label="邀请码"
						prop="userInfo.moblie"
						ref="item2"
						v-if="model1.userInfo.yqrid === null || model1.userInfo.yqrid == ''"
					>
					<u--input
							v-model="model1.userInfo.yqm"
							type="number"
							disabledColor="#ffffff"
							placeholder="请输入邀请码"
							border="none"
						></u--input>
									
					</u-form-item>
				</u--form>
				<u-button
					type="primary"
					text="保存"
					customStyle="margin-top: 50px"
					@click="submit"
					color="linear-gradient(to right, rgb(0, 150, 136), rgb(139, 195, 74))"
				></u-button>
			
			
			
			
			
			
			
		</view>
		
		
		<u-datetime-picker
					:show="showBirthday"
					:value="birthday"
					mode="date"
					closeOnClickOverlay
					@confirm="birthdayConfirm"
					@cancel="birthdayClose"
					@close="birthdayClose"
				></u-datetime-picker>
	</view>

</template>
<script>
export default {
	data() {
		return {
			tpList: [],
			model1: {
				userInfo: {
					name: '',
					moblie: '',
					birthday: '',
					head:'',
					yqrid: '',
				},
			},
			xm:'',
			sr:'',
			dh:'',
			fileList1:[],
			showBirthday: false,
			birthday: Number(new Date()),
			id:''
		}
	},
	onLoad(options) {
		this.id = options.id
		console.log(options)
		this.getHy()
	},
	methods: {
		async afterReada(e) {
			console.log("=============")
			this.tpList = [e.file];
		
		},
		getHy(){
			this.$http.post('/app/getHy', {}).then(res => {
				console.log(res)
				this.model1.userInfo.name = res.data.xm
				this.model1.userInfo.moblie = res.data.dh
				this.model1.userInfo.birthday = res.data.csrq
				this.model1.userInfo.yqrid = res.data.yqrid
			})
		},
		back(){
			uni.navigateBack()
		},
		birthdayConfirm(e) {
				this.showBirthday = false
				this.model1.userInfo.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
			
		},
		birthdayClose() {
			this.showBirthday = false
		
		},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		submit() {
			this.$http.post('/app/hy/updateHy', {
				id: this.id,
				xm:this.model1.userInfo.name,
				dh:this.model1.userInfo.moblie,
				csrq:this.model1.userInfo.birthday,
				yqm:this.model1.userInfo.yqm,
				// head:''
			}).then(res => {
				console.log(res)
				uni.showToast({
					title: '修改成功',
					icon: 'none'
				});
				setTimeout(()=>{
					let pages = getCurrentPages(); 
					let beforePage = pages[pages.length - 2]; 
					uni.navigateBack({
						success: function() {
							beforePage.onShow(); 
						}
					});

				},500)
			})
		},
	
		
	},
	mounted() {}
};
</script>


<style scoped lang="scss">
.wrap{
    width: 100%;
    height: 100vh;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    overflow: hidden;
    display: flex;
    background-image: url($imgUrl + "/lt_bg.jpg") ;
    background-repeat: no-repeat;
    flex-direction: column;
    .back{
     width: 95%;
     margin: 0 auto;
     padding-top:calc(var(--status-bar-height) + 60rpx) ;
      height: 120rpx;
      image{
       width: 76rpx;
       height: 64rpx;
      }
    }
    .content{
     width: 88%;
     margin: 20rpx auto;
	 /deep/.u-input__content__field-wrapper__field{
		background: #fff;
	 }
	 /deep/ .u-form-item__body__left__content__label{
		color: #fff !important;
		}
    }

	/deep/ .u-input__content__field-wrapper__field{
			text-align: left;
			color: #303133;
			height: 70rpx;
			font-size: 15px;
			flex: 1;
			line-height: 70rpx;
			padding-left: 10rpx;
			display: flex;
			align-items: center;
			.input-placeholder{
				width: 100% !important;
			}
	}
   }
/deep/ .u-icon__icon{
	font-size: 80rpx !important;
}
</style>
